<style type="text/css">
    .action-cell {
        margin-bottom: 20px;
        width: 100%;
        display: -webkit-box;
        display: -ms-flexbox;
        display: flex;
        -ms-flex-pack: distribute;
        justify-content: space-between;
        align-items: center;
        margin-right: 20%;
    }

    .search-block {
        display: flex;
        margin-bottom: 10px;
    }

    .input-search {
        margin-right: 10px;
    }
</style>
<template>
    <div>
        <div class="action-cell">
            <div class="list-action-btn">
                <Button type="error" @click="jumpPage('','StructuresAdd')">添加功能结构项</Button>
            </div>
            <div class="search-block">
                <i-input v-model="searchText">
                    <i-select slot="prepend" style="width: 80px">
                        <i-option value="接口路径">接口路径</i-option>
                        <i-option value="描述内容">描述内容</i-option>
                    </i-select>
                    <i-button slot="append" @click="searchEvent()" icon="ios-search"></i-button>
                </i-input>
            </div>
        </div>
            <Table :context="self" :data="tableData" :columns="tableColumns" stripe border></Table>
            <div style="margin: 10px;overflow: hidden">
                <div style="float: right;">
                    <Page :total="total" size="large" show-total :current="current" show-elevator show-sizer
                          @on-change="changePage"></Page>
                </div>
            </div>
        </div>
</template>
<script>
    import apiUtil from '../../assets/utils/api_util';

    export default {
        data() {
            return {
                self: this,
                tableData: [],
                total: 0,
                current: 1,
                //搜索
                searchText: '',
                tableColumns: [
                    {
                        title: "接口地址",
                        key: 'Interfaceurl',
                        align: 'center',
                    },
                    {
                        title: '功能项描述',
                        key: 'Description',
                        align: 'center',
                    },
                    {
                        title: '操作',
                        key: 'action',
                        width: 150,
                        align: 'center',
                        render: (h, params) => {
                            return h('div', [
                                h('Button', {
                                    props: {
                                        type: 'error',
                                        size: 'small'
                                    },
                                    style: {
                                        'margin-right': '10px',
                                    },
                                    on: {
                                        click: () => {
                                            this.remove(params.row.Id)
                                        }
                                    }
                                }, '删除'),
                            ])
                        }
                    }
                ]
            }
        },
        mounted() {
            this.mockTableData();
        },

        methods: {
            //跳转
            jumpPage: function (id, url) {
                //跳转
                let route = '';
                if (id.length > 0) {
                    route = {
                        path: url,
                        query: {
                            id: id,
                        }
                    }


                } else {
                    route = {
                        path: url,
                    };
                }

                this.$router.push(route);
            },
            mockTableData() {
                let that = this;

                let para = {};
                let params = that.$qs.stringify(para);

                this.$Loading.start();

                apiUtil.get(that, apiUtil.urls.ListStructures, para, function (res) {
                    that.$Loading.finish();
                    that.tableData = res.Msg;
                });

            },
            remove(id) {
                let that = this;
                this.$Modal.confirm({
                    title: '用户信息',
                    content: `是否删除吗`,
                    onOk: function () {
                        this.$Loading.start();
                        let para = {
                            id: id,
                        };
                        let params = that.$qs.stringify(para);
                        apiUtil.post(that, apiUtil.urls.DelStructure, params, function (res) {
                            that.mockTableData();
                        });
                    }
                })
            },
            changePage(row) {
                // 这里直接更改了模拟的数据，真实使用场景应该从服务端获取数据
                console.log("row", row);
                this.current = row;
                this.mockTableData();
            },
            searchEvent: function () {
                let that = this;
                let para = {
                    condition: this.searchText
                }
                let params = that.$qs.stringify(para);

                apiUtil.get(that, apiUtil.urls.SearchStructures, para, function (res) {

                    that.tableData = res.Msg;

                });
            }
        },
    }
</script>